package com.easy.threads.actuator;



import com.easy.common.IAutoScan;
import com.easy.config.log.MyLog;
import com.easy.threads.entity.Auto;
import com.easy.threads.factory.ThreadFactory;

import java.util.logging.Level;

/**
 * 描述: 自动扫描
 *
 * @author gwj
 * @date 2023年12月15日 14:51
 */

public class AutoScan extends Thread {


    private boolean start = true;

    private final Auto auto;

    public AutoScan(Auto auto) {
        this.auto = auto;
    }

    @Override
    public void run() {

        while (isStart()) {
            try {
                boolean autoScan = auto.isStartAutoScan();
                if(autoScan){
                    IAutoScan scanBean = auto.getScanBean();
                    if(scanBean == null){
                        throw new RuntimeException("执行对象为空");
                    }
                    scanBean.scan();
                }
            } catch (Exception e) {
                MyLog.getLogger().log(Level.SEVERE,"scan error ",e.getMessage());
            }

            ThreadFactory.sleep(auto.getIntervalTime());
        }
    }


    public boolean isStart() {
        return start;
    }

    public void setStart(boolean start) {
        this.start = start;
    }

    public Auto getAuto() {
        return auto;
    }
}
